<?php
namespace Admin\Controller;
class GoodsimgController extends CommonController {
    public function index(){
        $gid = I('get.gid');
        $goodsimg = M('goodsimg')->where('gi_g_id="'.$gid.'"')->select();
        $this->assign('gid',$gid);
        $this->assign('goodsimglist',$goodsimg);
        $this->show();
    }

    public function add(){
        $gid = I('get.gid');
        $this->assign('gid',$gid);
        $this->display();
    }

    public function insert(){
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath  =     './Uploads/Store/'; // 设置附件上传根目录
        $upload->savePath  =     ''; // 设置附件上传（子）目录
        $upload->subName = '';
        // 上传文件 
        $info = $upload->upload();
        if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
        }else{
            foreach($info as $file){
                $g_icon =  $file['savename'];
            }
        }

        $goodsimg = M('goodsimg');
        $goodsimg->g_icon = $g_icon;
        $goodsimg->gi_g_id =I('gid');
        $data = $goodsimg->add(); // 写入用户数据到数据库
        $this->success('数据保存成功！');
    }

    public function editFace(){
        $giid = $_POST['giid'];
        $gid = $_POST['gid'];
        $model = M('goodsimg');
        $data1['face'] = 0;
        $model->where('gi_g_id ="'.$gid.'"')->save($data1);
        $data2['face'] = 1;
        $model->where('gi_id ="'.$giid.'"')->save($data2);
    }

    public function delete(){
        $model = M('goodsimg');
        $model->delete($_POST['giid']);
    }
}